package com.atguigu.jinx.service.impl;

import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMessage;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

/**
 * Author:VEGA_KUANGQI
 * <p>
 * 2025/8/13
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class MailService {

    private final JavaMailSender mailSender;

    public void sendSimpleMail(String to, String subject, String content) throws MessagingException {
        MimeMessage message = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
        helper.setFrom("1059320355@qq.com");
        helper.setTo(to);
        helper.setSubject(subject);
        // true开启html的发送邮件
        helper.setText(content, false);
        mailSender.send(message);
    }
}
